package com.bawei.shopping2.widget

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class MyItemDecoration(var space:Int,var spanCount:Int):RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)

        outRect.top = space
        var position = parent.getChildAdapterPosition(view)
        if(position % spanCount == 0){//最左边
            outRect.left = space
            outRect.right = space/2
        }else if(position % spanCount == spanCount-1){//最右边
            outRect.left = space/2
            outRect.right = space
        }else{
            outRect.left = space/2
            outRect.right = space/2
        }


    }

}